package com.example.es.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * RestClintConfig:ES配置bean
 *
 * @author zhangxiaoxiang
 * @date 2022/04/05
 */
@Configuration
public class RestClintConfig extends AbstractElasticsearchConfiguration {
    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("192.168.10.129:9200")
                .build();
        System.out.println("初始化clientConfiguration = " + clientConfiguration);
        return RestClients.create(clientConfiguration).rest();
    }
}
